<script setup>
import { onMounted, ref } from "vue";
import { getCustomerService } from "~/api/user.js";

const emits = defineEmits(["close", "confirm"]);
const close = () => {
  emits("close");
};
const confirm = () => {
  emits("confirm");
};

const qrcode = ref("");
const loading = ref(false);
const getcode = async () => {
  try {
    loading.value = true;
    const res = await getCustomerService();
    qrcode.value = res.data?.url;
  } catch (err) {
    console.log(err);
  } finally {
    loading.value = false;
  }
};

onMounted(() => {
  getcode();
});
</script>

<template>
  <div class="dialog">
    <div class="dialog-box">
      <div class="header">
        <div class="left">
          <img src="~/assets/dialog-icon.png" alt="" />
          <span>客服微信</span>
        </div>
        <img class="close" src="~/assets/modal-close.png" alt="" @click="close" />
      </div>
      <div class="dialog-content" v-loading="loading">
        <p>请添加客服微信</p>
        <img :src="qrcode" alt="" />
      </div>
    </div>
  </div>
</template>

<style scoped lang="scss">
.dialog {
  position: fixed;
  top: 0;
  left: 0;
  bottom: 0;
  right: 0;
  background: rgba(25, 30, 40, 0.4);
  z-index: 999;
  display: flex;
  align-items: center;
  justify-content: center;
}

.dialog-box {
  width: 300px;
  background: #ffffff;
  border-radius: 12px 12px 12px 12px;
  padding: 24px;

  .header {
    display: flex;
    align-items: center;
    padding-bottom: 20px;

    .left {
      flex: 1;
      display: flex;
      align-items: center;

      img {
        width: 20px;
        height: 20px;
        margin-right: 4px;
      }

      span {
        font-size: 16px;
        color: #191e28;
        font-weight: bold;
      }
    }

    .close {
      width: 18px;
      height: 18px;
      cursor: pointer;
    }
  }
  .dialog-content {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    p {
      margin-bottom: 10px;
      font-weight: bold;
      margin-top: 20px;
    }
    img {
      width: 200px;
      height: 200px;
    }
  }
}
</style>

<style>
.dialog .el-select__wrapper {
  height: 40px;
}
.dialog .el-form--default.el-form--label-top .el-form-item .el-form-item__label {
  color: #191e28;
  font-weight: bold;
}
</style>
